const fs = require('fs');
const compiler = require('vue-template-compiler');

// 读取 .vue 文件
const filePath = './components/Manager-box.vue';
const fileContent = fs.readFileSync(filePath, 'utf8');

// 编译模板
const output = compiler.compileToFunctions(fileContent);

// 解析组件的 <script> 和 <style> 部分
const parts = compiler.parseComponent(fileContent);
let scriptCode = '';
if (parts.script) {
    scriptCode = parts.script.content;
}

// 生成最终的 JavaScript 代码
const jsCode = `
    const Vue = require('vue');
    const template = '${output.render}';
    const staticRenderFns = [${output.staticRenderFns.map(fn => `'${fn}'`).join(',')}];
    const componentOptions = {
        template,
        staticRenderFns,
        ${scriptCode}
    };
    module.exports = Vue.extend(componentOptions);
`;

// 保存为 .js 文件
fs.writeFileSync('./components/Manager-box.js', jsCode);